<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>盒子模型</title>
    <style>
      #d1, #d2 {
        width: 100px;
        height: 100px;
        border: 1px solid red;
      }
      #d1 {
        /*margin-top: 10px;
        margin-bottom: 20px;
        margin-left: 30px;
        margin-right: 40px;*/ /*单独设置某个方向 不推荐使用*/
        margin: 50px; /*同时设置四个方向*/
        margin: 20px 50px; /*上下20 左右50*/
        margin: 10px 20px 30px 40px;/*上右下左 从上方开始顺时针方向赋值*/
        margin: 0px auto; /*上下为0 左右居中*/
      }
      #s1 {
        /*行内元素(display值为inline) 设置上下外边距无效*/
        margin-top: 50px;
        margin-bottom: 50px;
      }
      #s2 {
        margin-left: 100px;
      }
      #d3 {
        width: 200px;
        height: 200px;
        background-color: red;
      }
      #d4 {
        width: 50px;
        height: 50px;
        background-color: blue;
        margin-left: 50px;
      }
    </style>
</head>
<body>
  <div id="d1">div1</div>
  <div id="d2">div2</div>
  <span id="s1">span1</span>
  <span id="s2">span2</span>
  <div id="d3">
    <div id="d4"></div>
  </div>
</body>
</html>